<template>
  <div class="app-header-sticky" :class="{show:y>=78}">
    <!-- v-show="y>=78" 不加这个，container会在访问另一个组件时跳出来，但是透明的，导致点击不到标签 -->
    <div v-show="y>=78" class="container">
      <h1 class="logo"><RouterLink to="/" /></h1>
      <!-- AppHeaderNav被复用，所以一个地方调用了他的css动画，其他地方的AppHeaderNav动画也会被调用 -->
      <AppHeaderNav />
      <div class="right">
        <router-link to="/">品牌</router-link>
        <router-link to="/">专题</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import AppHeaderNav from './AppHeaderNav.vue'
// import { onMounted, ref } from 'vue'
import { useWindowScroll } from '@vueuse/core'
export default {
  name: 'AppHeaderSticky',
  components: { AppHeaderNav },
  setup() {
    // 从useWindowScroll中结构出y属性
    const { y } = useWindowScroll()
    return { y }
  }
}
</script>

<style scoped lang='less'>
.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  transform: translateY(-100%);
  opacity: 0;
  &.show {
    transition: all 0.3s linear;
    transform: none;
    opacity: 1;
  }
  .container {
    display: flex;
    align-items: center;
  }
  .logo {
    display: block;
    width: 200px;
    height: 80px;
    background: url(../assets/images/logo.png) no-repeat  right 2px;

    // background-size属性：auto，cover，contain，自定义百分比。
    // background-size:  50% 100%;
    background-size:  contain;
  }
  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid @xtxColor;
    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover {
        color: @xtxColor;
      }
    }
  }
}
</style>
